
package com.thon.service.util;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @file DateAnalysis.java
 * @author manpiaoyi
 * @email manpiaoyi@126.com
 * @date 2014-11-9
 * @description 数据分析时间选择器
 */
public abstract class DateAnalysis<T> implements Analysis<T>{		

	protected Date startDate;
	protected Date endDate;
	protected Integer method;
	
	public Integer getMethod() {
		return method;
	}

	public void setMethod(Integer method) {
		this.method = method;
	}

	protected Integer StartToEndlength;
	
	public Integer getStartToEndlength() {
		return StartToEndlength;
	}

	public void setStartToEndlength(Integer startToEndlength) {
		StartToEndlength = startToEndlength;
	}

	public DateAnalysis(Date startDate,Date endDate)
	{
		this.startDate = startDate;
		this.endDate = endDate;
		
	}
	
	public void preAnalysis()
	{
		Calendar calendarEndDate = Calendar.getInstance();
		calendarEndDate.setTime(endDate);
		Calendar calendarStartDate = Calendar.getInstance();
		calendarStartDate.setTime(startDate);
		
		StartToEndlength = calendarEndDate.get(Calendar.YEAR)-calendarStartDate.get(Calendar.YEAR)+1;
				
		if(StartToEndlength != 1)
		{
			method = Calendar.YEAR;			
		}
		else if((StartToEndlength = calendarEndDate.get(Calendar.MONTH)-calendarStartDate.get(Calendar.MONTH)+1)!=1)
		{
			method = Calendar.MONTH;
		}		
		else if((StartToEndlength = calendarEndDate.get(Calendar.DAY_OF_MONTH) - calendarStartDate.get(Calendar.DAY_OF_MONTH)+1)!=1)
		{
			method = Calendar.DAY_OF_MONTH;
		}	
		else
		{
			method = Calendar.DAY_OF_MONTH;
		}
			
	}
	
	public abstract List<T> doAnalysis(List<T> datum);	

}